package com.luu.game.dao.impl;

import com.luu.game.dao.UserElfDao;
import com.luu.game.data.dto.ElfInfoDTO;
import com.luu.game.data.dto.UserElfSkillDTO;
import com.luu.game.data.entity.ElfEntity;
import com.luu.game.data.entity.UserElfEntity;
import com.luu.game.mapper.ElfMapper;
import com.luu.game.mapper.UserElfMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserElfDaoImpl implements UserElfDao {

    @Autowired
    private UserElfMapper userElfMapper;
    @Autowired
    private ElfMapper elfMapper;

    @Override
    public List<UserElfEntity> findAll() {
        return userElfMapper.findAll();
        // return userElfMapper.selectList(new LambdaQueryWrapper<UserElfEntity>().eq(UserElfEntity::getId,"1"));
    }

    /**
     * 查询角色精灵信息
     * @param id
     * @return
     */
    @Override
    public ElfInfoDTO findById(Integer id) {
        final ElfInfoDTO elfInfoDTO = userElfMapper.findUserElfAndElfInfo(id);
        return elfInfoDTO;
    }

    /**
     * 查询角色精灵技能
     * @param userElfId
     * @param skId
     * @return
     */
    @Override
    public UserElfSkillDTO findByUserElfIdAndSkId(Integer userElfId, Integer skId) {
        return userElfMapper.findByUserElfIdAndSkId(userElfId,skId);
    }

    @Override
    public void update(ElfInfoDTO elfInfoDTO) {
        UserElfEntity entity = new UserElfEntity();
        BeanUtils.copyProperties(elfInfoDTO,entity);
        userElfMapper.updateById(entity);
    }
}
